﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace Clipping.Utils
{
    /// <summary>
    /// 鼠标双击在DataGridRow时触发
    /// </summary>
    public class DataGridRowDoubleClickTrigger : TriggerBase<DataGrid>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.MouseLeftButtonDown += new MouseButtonEventHandler(AssociatedObject_MouseLeftButtonDown);
        }
		protected override void OnDetaching()
		{
			base.OnDetaching();
			this.AssociatedObject.MouseLeftButtonDown -= new MouseButtonEventHandler(AssociatedObject_MouseLeftButtonDown);

		}
        
		/// <summary>
		/// 处理鼠标左键点击事件
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount != 2)
                return;
            DependencyObject dep = (DependencyObject)e.OriginalSource;
            while ((dep != null) && !(dep is DataGridRow))
            {
                dep = VisualTreeHelper.GetParent(dep);
            }
            if (dep != null)
            {
                this.InvokeActions(null);
            }

        }

    }
}